package se.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Iterator;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;

import se.kernel.Cliente;

public class PanelClientes extends JPanel
{

    private static final long serialVersionUID = 1L;
    private JTextArea txtClientes = null;

    /**
     * This is the default constructor
     */
    public PanelClientes( )
    {
        super( );
        initialize( );
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize( )
    {
        GridBagConstraints gridBagConstraints = new GridBagConstraints( );
        gridBagConstraints.fill = GridBagConstraints.BOTH;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.gridx = 0;
        this.setSize( 588, 315 );
        this.setLayout( new GridBagLayout( ) );
        this.setBorder( BorderFactory.createTitledBorder( null, "Clientes", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font( "Lucida Grande", Font.PLAIN, 13 ), Color.black ) );
        JScrollPane scroll = new JScrollPane( getTxtClientes( ) );
        scroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
        scroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
        this.add( scroll, gridBagConstraints );
    }
    /**
     * This method initializes txtClientes
     * 
     * @return javax.swing.JTextArea
     */
    private JTextArea getTxtClientes( )
    {
        if( txtClientes == null )
        {
            txtClientes = new JTextArea( );
            txtClientes.setEditable( false );
            txtClientes.setFont( new Font( "Garamond", Font.PLAIN, 16 ) );
        }
        return txtClientes;
    }

    public void actualizarListaClientes( Iterator<Cliente> clientes )
    {
        txtClientes.setText( "" );
        while( clientes.hasNext( ) )
            txtClientes.append( clientes.next( ) + "\n" );
    }

} // @jve:decl-index=0:visual-constraint="10,10"
